<#include "layout/template.ftl"/>

<@htmlHead title="导入商品">
   
</@htmlHead>


 
<@htmlBody 'commodity' 'goods'>

	<!-- breadcrumbs begin -->
	<#include "layout/breadcrumbs.ftl">
	<@breadcrumbs '商品管理' '导入商品'></@breadcrumbs>
	<!-- breadcrumbs end -->

	<!-- page-content begin -->
	<div class="page-content">
			
			<!-- page-header begin -->
			<div class="page-header">
					<h1>
						导入商品
					</h1>
			</div>
			<!-- page-header end -->
			
			<div class="col-md-8 col-md-offset-2" style="background-color:#CEFFCE">
					<p>温馨提示	：</p>
					<p>请先下载导入模板，按照模板导入数据！<a href="${resources}/file/goods.xlsx"   > 下载</a></p>
			</div>
			
			<!-- page-body begin -->
			<div class="row">	
				<div class="col-md-8 col-md-offset-2">
					
						<!-- 表单开始 -->
						<form class="form-horizontal" id="validation-form" method="post" action="${path}/manage/commodity/goods/import"  enctype="multipart/form-data">
					
						<!-- edit-basic: 编辑信息面板 begin -->
						<div id="edit-basic" class="" style="border: 1px solid #98DAF0;padding: 0px 15px;margin-top: 10px;">
										
							<h4 class="header blue bolder smaller">导入数据</h4>
										
							<div style="padding:10px;height:80px;">
							 <#if market.id!=1>
							<div class="form-group">	
								<label class="control-label col-md-2 no-padding-right" for="cpname">商品分类:</label>
								<div class="col-md-10">
									<div class="clearfix">
											<select id="categoryid" name="categoryid" style="width: 50%">
											<option value="">请选择商品分类</option>
											<#list categoryLists as categories>
												<option value="${categories.id}">${categories.name}</option>
											</#list>
										</select>
									</div>
								</div>
							</div> 
							<#else>
							<div class="form-group">	
								<label class="control-label col-md-2 no-padding-right" for="cpname">商品父分类:</label>
								<div class="col-md-10">
									<div class="clearfix">
											<select id="categoriesid" name="categories.id" style="width: 50%">
											<option value="">请选择商品父分类</option>
											<#list categoryLists as categories>
												<option value="${categories.id}">${categories.name}</option>
											</#list>
										</select>
									</div>
								</div>
							</div>
							<div class="form-group">	
								<label class="control-label col-md-2 no-padding-right" for="cpname">商品子分类:</label>
								<div class="col-md-10">
									<div class="clearfix">
											<select id="categoryid" name="categoryid" style="width: 50%">
											<option value="">请选择商品子分类</option>
											<#list categoryList as category>
												<option value="${category.id}">${category.name}</option>
											</#list>
										</select>
									</div>
								</div>
							</div>
							</#if>
						</div>
											<br/>
										<div style="padding:10px;height:80px;">
											<div class="col-md-4 col-md-offset-2">
												<input type="text" style="width:100%;height:44px;" name="fileField" value="" id="customerpath">
											</div>
											
											<div class="col-md-2">
												<a onclick="document.getElementById('file').click();"  class="btn btn-warning"> 选择EXCEL文件</a>
				                        		<input type="file" style="display: none" accept="application/msexcel" name="file" id="file" class="upload_file1" onchange="document.getElementById('customerpath').value=this.value;"/>
											</div>
										</div>
										
									</div>
									<!-- edit-basic: 编辑信息面板 end -->
								
								
						</form>
						<!-- 表单结束 -->
						
						


						<!-- 提交开始 -->
	                    <div class="form-group">
	                    	<div class="col-md-8 center">
		                    	<button id="form-submit" type="button" onclick="mysubmit('validation-form')"  class="btn btn-primary">
									<i class="fa fa-save align-top bigger-125"></i>保存
								</button>
							 
								<button type="reset" class="btn">
									<i class="fa fa-pencil align-top bigger-125"></i>重置
								</button>
							</div>					
                   		</div>
						<!-- 提交结束  -->
				</div>
			</div>
			<!-- page-body end -->
		
	</div>		
	<!-- page-content end -->

</@htmlBody>



<@htmlBodyScript>


	<!-- 上传控件 -->
	<script type="text/javascript" src="${resources}/assets/js/ajaxfileupload.js"></script>
	<script src="${resources}/plugins/letsun-upload/upload.js"></script>
	<script>
	    /**
	     * 功能 : 提交表单
		 */
	 	function mysubmit(form){
	    	
	 		$("#"+form).submit();
	 	}
		
	</script>

	<!-- 验证框架 -->	
	<script src="${resources}/plugins/jquery-validation/jquery.validate.min.js"></script>
	<script src="${resources}/plugins/jquery-validation/messages_zh.min.js"></script>
	
	<script type="text/javascript">

			jQuery.validator.addMethod("isName", function(value, element) {       
	 			var corpName =  /^[\u0391-\uFFE5\w\-\s\.]{1,50}$/;
  				 return this.optional(element) || corpName.test(value);       
 			}, "请使用汉字、英文字母、数字、下划线、减号、空格或点");   
 			
	
			$('#validation-form').validate({
				errorElement: 'div',
				errorClass: 'help-block',
				focusInvalid: false,
				rules: {
					"categoryid": {
						required:true
					},
					"categories.id":{
						required:true
					}
				},
		
				messages: {
				},
		
		
				highlight: function (e) {
					$(e).closest('.form-group').removeClass('has-info').addClass('has-error');
				},
		
				success: function (e) {
					$(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
					$(e).remove();
				},
		
				errorPlacement: function (error, element) {
					if(element.is('input[type=checkbox]') || element.is('input[type=radio]')) {
						var controls = element.closest('div[class*="col-"]');
						if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
						else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
					}
					else if(element.is('.select2')) {
						error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
					}
					else if(element.is('.chosen-select')) {
						error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
					}
					else error.insertAfter(element.parent());
				},
		
				invalidHandler: function (form) {
				}
			});
			
			$("#categoriesid").change(function(){
			var pid = $(this).find("option:selected").val();
			if(pid==""){
				//alert("请选择父节点");
				return;
			}
			$.ajax({
				url:"${path}/manage/commodity/goods/ajaxChild?pid="+pid,
				type:"post",
				success:function(data){
					var html = "<option value=''>请选择</option>";
					if(data.length>0){
						for(var i=0;i<data.length;i++){
							html+="<option value='"+data[i].id+"'>"+data[i].name+"</option>";						}
					}
					$("#categoryid").html(html);
				}
			})
		})
	 	
			
 //选择商品副分类
 	  <#if market.id==4>
      $("#categoryid").change(function(){
         
          var selectVal = $(this).find("option:selected").text();
          if(selectVal == "积分商城"){
             $("#limitType").val(0);
          }
            if(selectVal == "限时抢"){
              $("#limitType").val(1);
          }
            if(selectVal == "限量抢"){
             $("#limitType").val(2);
          }
      
      });
       </#if>
		
			
	</script>


</@htmlBodyScript>